package org.example;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class JdbcPrepareLike {
    static Connection con;
    static {

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        try {
              con = DriverManager.getConnection("jdbc:mysql://121.41.77.32:3306/school_demo?useSSL=False","root","123456");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
    public static void like(String user) throws SQLException {
        String sql = "select * from emp where ename like ?";
        PreparedStatement preparedStatement = con.prepareStatement(sql);
        preparedStatement.setString(1,user);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()){
            System.out.println("符合条件");
            while (resultSet.next()){
                String ename = resultSet.getString("ename");
                System.out.println(String.format("%s",ename));
            }
        }else {
            System.out.println("不符合条件");
        }
        preparedStatement.close();
    }
    public static void main(String[] args) throws SQLException {
        like("%O%");
    }
}
